package org.zpmis.api.http;

import org.zpmis.api.business.CustomerCarePlanWebService;
import org.zpmis.common.base.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.customer.qo.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
* created with CodeGenerator
* description:
* @author  Ljx
* date: 2021-8-16
* time: 13:24:07
*/
@RestController
@RequestMapping("/care/plan")
@Slf4j
public class CustomerCarePlanController extends BaseController{

    @Resource
    private CustomerCarePlanWebService customerCarePlanWebService;

    /**
     * 新增客户关怀计划
     * @param addCustomerCarePlanQo
     * @return
     */
    @PostMapping("/addCustomerCarePlan")
    public PlatformResult addCustomerCarePlan(@RequestBody AddCustomerCarePlanQo addCustomerCarePlanQo){
        try {
            customerCarePlanWebService.addCustomerCarePlan(addCustomerCarePlanQo);
        } catch (BusinessException e) {
            log.error("[CustomerCarePlanController]---addCustomerCarePlan--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[CustomerCarePlanController]---addCustomerCarePlan--->Exception:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }

    /**
     * 修改意向客户关怀计划
     * @param editCustomerCarePlanQo
     * @return
     */
    @PostMapping("/editCustomerCarePlan")
    public PlatformResult editCustomerCarePlan(@RequestBody EditCustomerCarePlanQo editCustomerCarePlanQo){
        try {
            customerCarePlanWebService.editCustomerCarePlan(editCustomerCarePlanQo);
        } catch (BusinessException e) {
            log.error("[CustomerCarePlanController]---editCustomerCarePlan--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[CustomerCarePlanController]---editCustomerCarePlan--->Exception:",e);
            return PlatformResult.failure();
        }
        return PlatformResult.success();
    }

    /**
     * 关怀计划列表查询
     * @param carePlanListQo
     * @return
     */
    @PostMapping("/customerCarePlanList")
    public PlatformResult customerCarePlanList(@RequestBody CustomerCarePlanListQo carePlanListQo){
        try {
            return PlatformResult.success(customerCarePlanWebService.planList(carePlanListQo));
        } catch (Exception e) {
            log.error("[CustomerCarePlanController]---customerCarePlanList--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 获取客户关怀计划详情
     * @param getCustomerCarePlanDetailQo
     * @return
     */
    @PostMapping("/getCustomerCarePlanDetail")
    public PlatformResult getCustomerCarePlanDetail(@Valid @RequestBody GetCustomerCarePlanDetailQo getCustomerCarePlanDetailQo){
        try {
            return PlatformResult.success(customerCarePlanWebService.getCustomerCarePlanDetail(getCustomerCarePlanDetailQo));
        } catch (BusinessException e) {
            log.error("[CustomerCarePlanController]---getCustomerCarePlanDetail--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[CustomerCarePlanController]---getCustomerCarePlanDetail--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 执行客户关怀计划
     * @param executeCustomerCarePlanQo
     * @return
     */
    @PostMapping("/executeCustomerCarePlan")
    public PlatformResult executeCustomerCarePlan(@Valid @RequestBody ExecuteCustomerCarePlanQo executeCustomerCarePlanQo){
        try {
            customerCarePlanWebService.executeCustomerCarePlan(executeCustomerCarePlanQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[CustomerCarePlanController]---executeCustomerCarePlanQo--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[CustomerCarePlanController]---executeCustomerCarePlanQo--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 删除客户关怀计划
     * @param deleteCusomerCarePlanQo
     * @return
     */
    @PostMapping("/deleteCustomerCarePlan")
    public PlatformResult deleteCustomerCarePlan(@Valid @RequestBody DeleteCusomerCarePlanQo deleteCusomerCarePlanQo){
        try {
            customerCarePlanWebService.deleteCustomerCarePlan(deleteCusomerCarePlanQo);
            return PlatformResult.success();
        } catch (BusinessException e) {
            log.error("[CustomerCarePlanController]---deleteCustomerCarePlan--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[CustomerCarePlanController]---deleteCustomerCarePlan--->Exception:",e);
            return PlatformResult.failure();
        }
    }
}
